class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        if len(prices) == 1 or len(prices) == 0:
            return 0
        mins = prices[0]
        maxp = 0
        for i in range(len(prices)):
            if mins > prices[i]:
                mins = prices[i]
            else:
                maxp = max(prices[i]-mins,maxp)
        return maxp



        # a = set()
        # for i in range(len(prices)):
        #     if i + 1 <len(prices) and  prices[i] > max(prices[i+1:len(prices)]):
        #         continue
        #     else:
        #         q = max(prices[i:])
        #         max1 = q - prices[i]
        #         # max1 = max(max1,tmp)
        #         a.add(max1)
        # if len(a) == 1:
        #     return 0
        # else:
        #     return max(a)

m = [7,1,5,3,6,4]
s = Solution()
a = s.maxProfit(m)
print(a)




